<template>
  <div id="md-preview">
    <h1 class="green">{{ title }}</h1>
    <v-md-preview :text="content"></v-md-preview>
  </div>
</template>

<script>
import httpRequest from '../utils/axiosInstance.js'
export default {
  data() {
    return {
      title: 'Hello World',
      content: '## SUCCESS 😀'
    }
  },
  created() {
    // 请求数据
    this.getData()
  },
  methods: {
    getData: function () {
      // md_id，结果是：'?mdId=63c16280ce3e64f46cc41d6f'这种
      var search = location.search;
      if (!search) {
        return null
      }
      // 请求数据
      httpRequest({
        method: 'get',
        // 结果：/md-preview?mdId=xxxx
        url: `/md-preview${search}`
      }).then((resp) => {
        console.log('data', resp.data)
        const res = resp.data
        if (res.code == 200) {
          this.title = res.data.mdTitle
          this.content = res.data.mdContent
        }
      }).catch(e => console.log(e))
    },
  },
}
</script>
